<%@page import="ae.pcfc.etks.online.itworx.ehs.web.enums.RequestStatus"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.enums.RequestAction"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.enums.UserType" %>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.util.UtilCommon" %>
<%@page import="java.math.*,java.text.*" %>
<%@include file="/WEB-INF/view/include.jsp"%>
<%@page
	import="ae.pcfc.etks.online.itworx.ehs.web.constants.GlobalConstants"%>
<%
	String type = (String) request.getParameter("type");
	if (null == type) {
		type = "";
	}
%>

<script type="text/javascript">

	function submitForm(action)
	{
		document.getElementById("action").value=action;
		document.forms[0].submit();
	}

	var contextPath = '<%=request.getContextPath()%>';
	function openFnpWindow() {
		window.open(contextPath + "/fnp/fnpMapping.htm", "Fees_Calculations");
	}
</script>

<script>
	
	function validate(tableID, action) {
		var errorDivValue = "";
		var location = document.getElementById("location").value;
		var contactPersonName = document.getElementById("contactPersonName").value;
		var telephone = document.getElementById("telephone").value;
		var alternativeEmail = document.getElementById("alternativeEmail").value;
		var bccValue = document.getElementById("bcc").value;
		var optionalMail = document.getElementById("optionalMail").value;
		var remarks = document.getElementById("remarks").value;
		var mailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		//var telephoneReg = /^[0][0][1-9]{13}$/;
		//var telephoneReg = /^[0][0][1-9]{1}\d{0,2}\d{9,10}$/;
		var telephoneReg = /^([0][0][1-9]{1}\d{0,2})?\d{9,10}$/;
		var isValid = true;
		var isBCC = false;
		var isBccFound = true;

		if(action == "Non-Compliance_comments_exist"){
			isValid=validateIMSComments();
		}
		if(action == "create" || action == "submit"){
			if(null != remarks && remarks != "" && remarks.length > 500){
				isValid = false;
				errorDivValue += "<br>"
						+ '<spring:message code="Length.ofcRequestModel.remarks"/>';
			}
			if(bccValue != null && bccValue != ""){
				isBCC = true;
				isBccFound = false;
			}

			if (location == null || location == "" || location == '<spring:message code="label.request.select"/>') {
				isValid = false;
				errorDivValue += "<br>"
						+ '<spring:message code="NotEmpty.ofcRequestModel.location"/>';
			}

			if (contactPersonName == null || contactPersonName == "") {
				isValid = false;
				errorDivValue += "<br>"
						+ '<spring:message code="NotEmpty.ofcRequestModel.contactPersonName"/>';
			}

			if (telephone == null || telephone == "") {
				isValid = false;
				errorDivValue += "<br>"
						+ '<spring:message code="NotEmpty.ofcRequestModel.telephone"/>';
			}else{
				if(telephoneReg.test(telephone) == false){
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="TelephoneReg.ofcRequestModel.telephone"/>';
				}
			}
		

			if (alternativeEmail == null || alternativeEmail == "") {
				isValid = false;
				errorDivValue += "<br>"
						+ '<spring:message code="NotEmpty.ofcRequestModel.alternativeEmail"/>';
			}else{
				if(mailReg.test(alternativeEmail) == false) {
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="Mail.ofcRequestModel.alternativeEmail"/>';
				   }
			}

			if (optionalMail != null && optionalMail != "") {
				if(mailReg.test(optionalMail) == false) {
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="Mail.ofcRequestModel.optEmail"/>';
				   }
			}
			
			//validate IMSLogId
			var imsLogId = document.getElementById("imsLogId");
			if(imsLogId != null){
				var imsLogIdValue = imsLogId.value;
				if(null == imsLogIdValue || imsLogIdValue == ""){
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="NotEmpty.ofcRequestModel.imsLogId"/>';
				}
			}

			//validate AmendmentType
			var amendmentType = document.getElementById("amendmentType");
			if(amendmentType != null){
				var amendmentTypeValue = amendmentType.value;
				if(null == amendmentTypeValue || amendmentTypeValue == "" || amendmentTypeValue == '<spring:message code="label.request.select"/>'){
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="NotEmpty.ofcRequestModel.amendmentType"/>';
				}
			}
			
			document.getElementById("errorDiv").innerHTML = errorDivValue;
		}
		
		var table = document.getElementById(tableID);
		var isReseatFound = true;
		if ((null == table || table.rows.length <= 1) && (action == "payment_done" ||  action == "additional_payment_done")) {
			isReseatFound = false;
			isValid = false;
		}
		var fileExtensionValid = true;
		if (table != null) {
			var rowCount = table.rows.length;

			for ( var i = 1; i < rowCount; i++) {
				var documentTypeEnglishId = document.getElementById("documents"
						+ (i - 1) + ".documentType.englishName");
				var documentTypeArabicId = document.getElementById("documents"
						+ (i - 1) + ".documentType.arabicName");
				var fileNameId = document.getElementById("multipartFiles"
						+ (i - 1));

				if(fileNameId !=null){
					fileExtensionValid  = validateFileType(fileNameId);
					if(!fileExtensionValid){
						break;
					}
				}
				
				var documentTypeId = "";
				if (documentTypeEnglishId == null
						&& documentTypeArabicId == null) {
					document.forms[0].submit();
				} else if (documentTypeEnglishId != null) {
					documentTypeId = documentTypeEnglishId;
				} else if (documentTypeArabicId != null) {
					documentTypeId = documentTypeArabicId;
				}
				var documentType = documentTypeId.value;

				if(isBCC){
					if(documentType == '<spring:message code="document.name.bcc"/>'){
						isBccFound = true;
					}
				}
				
				if (fileNameId == null) {
					if ((action == "payment_done" || action == "additional_payment_done")) {
							isReseatFound = false;
						} else {
							isReseatFound = true;
						}
					continue;
				}

				if (fileNameId == null) {
					document.forms[0].submit();
				}
				var fileName = fileNameId.value;
				if (documentType == null || documentType == "" || documentType == '<spring:message code="label.request.select"/>') {
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="error.ofcRequestModel.documentType.empty"/>';
					//document.getElementById("errorDiv").innerHTML = errorDivValue;
					//break;
				}
				if (fileName == null || fileName == "") {
					isValid = false;
					errorDivValue += "<br>"
							+ '<spring:message code="error.ofcRequestModel.multipartFile.empty"/>';
					//document.getElementById("errorDiv").innerHTML = errorDivValue;
					//break;
				}

				if ((action == "payment_done" || action == "additional_payment_done") && fileNameId != null) {
					if (documentType == '<spring:message code="document.name.paymentReceipt"/>') {
						isReseatFound = true;
					} else {
						isReseatFound = false;
					}
				}

				if (!isValid && i >= rowCount-1) {
					if (!isReseatFound) {
						errorDivValue += "<br>"
							+ '<spring:message code="error.ofcRequestModel.documentType.reset"/>';
							document.getElementById("errorDiv").innerHTML = errorDivValue;
						return;
					}else if(!isBccFound){
						errorDivValue += "<br>"
							+ '<spring:message code="error.ofcRequestModel.amendmentType.facExpansion"/>';
							document.getElementById("errorDiv").innerHTML = errorDivValue;
						return;
					}
				}
				if(!isValid){
					document.getElementById("errorDiv").innerHTML = errorDivValue;
					break;
				}
				
			}
			if(!fileExtensionValid){
				errorDivValue += "<br>"
					+ '<spring:message code="error.ofcRequestModel.pdf.uploadDocument"/>';
				document.getElementById("errorDiv").innerHTML = errorDivValue;
				isValid = false;
			}
		}
		if (!isReseatFound) {
			errorDivValue += "<br>"
					+ '<spring:message code="error.ofcRequestModel.documentType.reset"/>';
			document.getElementById("errorDiv").innerHTML = errorDivValue;
			isValid = false;
		}
		if (!isBccFound) {
			errorDivValue += "<br>"
					+ '<spring:message code="error.ofcRequestModel.bcc.uploadDocument"/>';
			document.getElementById("errorDiv").innerHTML = errorDivValue;
			isValid = false;
		}
		if (isValid) {
			//document.forms[0].submit();
			submitForm(action);
			return;
		}
		document.body.scrollTop = document.documentElement.scrollTop = 0;
	}

	function populateDocumentTypeList(){
		return jQuery.parseJSON(document.getElementById("documentTypesJSON").value);
	}

	function addRow(tableID, lang) {

		var types =  populateDocumentTypeList();
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;

		// check on the length if greater than (configured value) return error
		if (rowCount > <%= UtilCommon.getGeneralMapAsInteger(GlobalConstants.MAX_UPLOADED_DOC_COUNT_KEY) %>) {
			document.getElementById("errorDiv").innerHTML = '<spring:message code="error.ofcRequestModel.multipartFile.numbers"/>';
			return;
		}

		var row = table.insertRow(rowCount);

		//Document Type Name and ID
		var cell1 = row.insertCell(0);
		var element1 = document.createElement("select");
		var opt = document.createElement("option");
		opt.value = '<spring:message code="label.request.select"/>';
		opt.text = '<spring:message code="label.request.select"/>';
		element1.options.add(opt);
		for(var k = 0; k<types.length; k++){
			var option = document.createElement("option");
			option.value = types[k].id;
			if(lang == "ar"){
				option.text = types[k].arabicName;
			}else{
				option.text = types[k].englishName;
			}
			
			element1.options.add(option);
		}

		element1.name = "documents[" + (rowCount - 1)
		+ "].documentType.id";
		element1.id = "documents" + (rowCount - 1) + ".documentType.id";
		element1.className="fm-opt";
		element1.style.marginBottom = "0px";
		
		var hiddenElement = document.createElement("input");
		hiddenElement.type = "hidden";
		//hiddenElement.value = element1.options[element1.selectedIndex].text;
		
		if (lang == "ar") {
			hiddenElement.name = "documents[" + (rowCount - 1)
					+ "].documentType.arabicName";
			hiddenElement.id = "documents" + (rowCount - 1)
					+ ".documentType.arabicName";
		} else {
			hiddenElement.name = "documents[" + (rowCount - 1)
					+ "].documentType.englishName";
			hiddenElement.id = "documents" + (rowCount - 1)
					+ ".documentType.englishName";
		}
		element1.onchange = function(){
			getSelectedDocumentType(this, lang);
		};
		cell1.appendChild(element1);
		hiddenElement.style.display="none";
		//cell1.appendChild(hiddenElement);
		row.appendChild(hiddenElement);

		//Uploading File
		var cell2 = row.insertCell(1);
		var element2 = document.createElement("input");
		element2.type = "file";
		element2.name = "multipartFiles[" + (rowCount - 1) + "]";
		element2.id = "multipartFiles" + (rowCount - 1);
		element2.size="40";
		element2.accept="pdf";
		//element2.onchange=function(){
		//	validateFileType(this);
		//};
		cell2.appendChild(element2);

		//Deleting Action
		$.alerts.okButton='<spring:message code="label.document.delete.confirm.yes"/>';
		$.alerts.cancelButton='<spring:message code="label.document.delete.confirm.no"/>';
		var cell3 = row.insertCell(2);
		cell3.className = "actions";
		var element3 = document.createElement("img");
		element3.src = "resources/images/common/cancel_doc_icon.png";
		element3.title = '<spring:message code="label.document.delete.confirm.toolTip"/>';
		element3.onclick = function() {
			jConfirm('<spring:message code="label.document.delete.confirm.message"/>','', function(r){
				if(r){
					deleteRow(tableID, element3.parentNode.parentNode.rowIndex,
							'${requestScope.requestContextAttribute.locale.language}', '<spring:message code="label.document.delete.successMessage"/>');
				}
			}
		);
		};
		cell3.appendChild(element3);

	}
	function validateFileType(sender){
		var validExts = new Array(".pdf");
	    var fileExt = sender.value;
	    fileExt = fileExt.substring(fileExt.lastIndexOf('.')).toUpperCase();
	    //alert("fileExt: " + fileExt);
		for(var loop=0;loop<validExts.length;loop++){
		    if (validExts[loop].toUpperCase() == fileExt) {
		      //alert("Invalid file selected, valid files are of " +
		      //         validExts.toString() + " types.");
		      return true;
		    }
		}
		return false;
	}
	
	function getSelectedDocumentType(typeObject, lang){
		var id = typeObject.id;
		var typeId = "";
		if (lang == "ar") {
			typeId = id.substring(0, id.lastIndexOf('.')) + ".arabicName";
		}else{
			typeId = id.substring(0, id.lastIndexOf('.')) + ".englishName";
		}
		var documentTypeName = document.getElementById(typeId);
		documentTypeName.value = typeObject.options[typeObject.selectedIndex].text;
	}

	function validateIMSComments(){
		var table = document.getElementById('Table2');
		if(table != null){
			var rowCount = table.rows.length;
			for ( var i = 1; i < rowCount; i++) {
				var commentCtl = document.getElementById("comments" + (i-1) + ".reply"); 
				if(null != commentCtl){
					var replyValue = document.getElementById("comments" + (i-1) + ".reply").value;
					if(null == replyValue || replyValue == ""){
						document.getElementById("errorDiv").innerHTML = '<spring:message code="error.ofcRequestModel.nonComplianceComment.reply"/>';
						return false;
					}else if(replyValue.length > 500){
						document.getElementById("errorDiv").innerHTML = '<spring:message code="error.ofcRequestModel.nonComplianceComment.reply.length"/>';
						return false;
					}
				}
		}
	}
	return true;
}
</script>




<form:form modelAttribute="<%=GlobalConstants.OFC_REQUEST_MODEL%>"
	name="createRequest" id="createRequest" method="POST"
	action='${((empty ofcRequestModel.status) || (null == ofcRequestModel.status)) ? "client/create.htm" : "client/viewDetails.htm"}'
	enctype="multipart/form-data">

	<form:hidden path="status"/>
	<form:hidden path="serviceName"/>
	<div style="color:#ED0000;font-size:12px;margin:0 0 10px 10px" id="errorDiv">
		<spring:bind path="ofcRequestModel.*">
			<c:forEach items="${status.errorMessages}" var="error">
				<c:out value="${error}" />
				<br />
			</c:forEach>
		</spring:bind>
	</div>
	
	<input type="hidden" id="documentTypesJSON"
		value="<c:out value="${documentTypesJSON}" escapeXml="true"/>" />
		<c:if test="${(null != ofcRequestModel.status) && (not empty ofcRequestModel.status)}">
			<fieldset>
				<legend>
					<spring:message code="label.request.requestDetails" />
				</legend>
			</fieldset>
			<div class="t_form-left">
				<label><spring:message code="label.request.requestId" />:</label>				
				<input  class="t_form-fld-readonly" value="${ofcRequestModel.serviceName}_${ofcRequestModel.type}_<fmt:formatDate value="${ofcRequestModel.creationDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_ID_DATE_FORMAT%>" />_${ofcRequestModel.id}" title="${ofcRequestModel.serviceName}_${ofcRequestModel.type}_<fmt:formatDate value="${ofcRequestModel.creationDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_ID_DATE_FORMAT%>" />_${ofcRequestModel.id}" readonly="readonly"/>
			</div>
			<div class="t_form-right">
				<label><spring:message code="label.request.reqStatus" /></label>
				
				<input value="<spring:message code="${ofcRequestModel.status}"/>" readonly="readonly" class="t_form-fld-readonly"/>
			</div>
			<div class="brk"></div>
		</c:if>
		
		<fieldset>
			<legend>
				<spring:message code="label.request.company.nameeng.label" />
			</legend>
		</fieldset>
		<div class="t_form-left">
			<label> <spring:message code="label.request.company.nameeng" />
			</label>
			<form:input path="companyNameEnglish" name="input" type="text"
				readonly="true" class="t_form-fld-readonly" title="${ofcRequestModel.companyNameEnglish}"/>

		<label><spring:message code="label.request.TradeLicenceNo" />
		</label>

		<form:input path="licenseNumber" class="t_form-fld-readonly"
			readonly="true"/>

		<label><spring:message code="label.request.buisnessUnit" /> 
		</label>
		<form:input path="businessUnit" type="text" readonly="true"
			class="t_form-fld-readonly" maxlength="50" title="${ofcRequestModel.businessUnit}"/>

			<label> <spring:message code="label.request.mailMail" /> </label>
			<form:input path="mainEmail" type="text" readonly="true"
				class="t_form-fld-readonly" maxlength="50" />

			<label><spring:message code="label.request.requestedBy" /> </label>
			<form:input type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}" path="requestedBy"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="50" />

			<label> <spring:message code="label.request.remarks" /> </label>
			<form:textarea path="remarks" naem="textarea" class="t_address ${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"></form:textarea>

		</div> <!--form-left-end-->

		<div class="t_form-right">
			<label> <spring:message code="label.request.company.namearab" />
			</label>
			<form:input path="companyNameArabic" type="text" readonly="true"
				class="t_form-fld-readonly" title="${ofcRequestModel.companyNameArabic}"/>

			
			

			<label><spring:message code="label.request.location" /><span
				class="t_star"><spring:message code="label.required" /> </span>:</label>
				<c:choose>
					<c:when test="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status))}">
						<form:select name="select" class="fm-opt" path="location">
						<option>
							<spring:message code="label.request.select" />
						</option>
						<form:options items="${ofcRequestModel.locations}"/>
				</form:select>
					</c:when>
					<c:otherwise>
						<form:input path="location" class="t_form-fld-readonly" readonly="true"/>
					</c:otherwise>
				</c:choose>
			

			<label><spring:message code="label.request.bcc" /> </label>
			<form:input path="bcc" type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="30" />

			<label> <spring:message code="label.request.optionalMail" />
			</label>
			<form:input type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}" path="optionalMail"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="50" />
			<label> <spring:message code="label.request.date" /> </label>
			<form:input path="creationDate" type="text" readonly="true"
				class="t_form-fld-readonly" />
			
			<label><spring:message code="label.request.activity" /> </label>
			<c:choose>
				<c:when test='${requestScope.requestContextAttribute.locale.language eq "ar"}'>
					<form:hidden path="engActivity" id="engActivity" title="${ofcRequestModel.engActivity}"/>
					<form:textarea path="arActivity" type="text" readonly="true"
						class="t_address t_form-fld-readonly" id="arActivity" title="${ofcRequestModel.arActivity}"/>
				</c:when>
				<c:otherwise>
					<form:textarea path="engActivity" type="text" readonly="true"
						class="t_address t_form-fld-readonly" id="engActivity" title="${ofcRequestModel.engActivity}"/>
					<form:hidden path="arActivity" id="arActivity" title="${ofcRequestModel.arActivity}"/>
				</c:otherwise>
			</c:choose>
		</div> <!--form right close-->

		<div class="brk"></div>
		<fieldset>
			<legend>
				<spring:message code="label.request.contactPerson.info" />
			</legend>
		</fieldset>
		<div class="t_form-left">
			<label> <spring:message
					code="label.request.contactPerson.name" /><span class="t_star"><spring:message
						code="label.required" /> </span>:</label>
			<form:input path="contactPersonName" name="input" type="text"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="50" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}" />


			<label><spring:message
					code="label.request.contactPerson.telephone" /><span
				class="t_star"><spring:message code="label.required" /> </span>:</label>
			<form:input path="telephone" name="input" type="text"
				class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="30" />


			<label><spring:message code="label.request.faxNo" /> </label>
			<form:input type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}" path="fax"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="30" />
		</div> <!--form-left-end-->

		<div class="t_form-right">
			<label> <spring:message
					code="label.request.contactPerson.mobile" /> </label>
			<form:input path="mobile" name="input" type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="30" />
			<label> <spring:message
					code="label.request.contactPerson.email" /><span class="t_star"><spring:message
						code="label.required" /> </span>:</label>
			<form:input path="alternativeEmail" name="input" type="text"
				class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}"
				readonly="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}"
				maxlength="50" />

	</div><!--form right close--><c:choose>
		<c:when test="${ofcRequestModel.type eq 'Amendment'}">
			<div class="brk"></div>
			<div id="amendment">
				<fieldset>
					<legend>
						<spring:message code="label.request.amendmentType" />
					</legend>
				</fieldset>
				<div class="t_form-left">
					<label class="multiple_selection_label"><spring:message code="label.request.amendmentTypeList" />
						<span class="t_star"><spring:message code="label.required" />
					</span>:</label>

                    <c:if test="${((null != ofcRequestModel.status) and (ofcRequestModel.status != 'Return_For_Update') and (not empty ofcRequestModel.status))}">
                    	<form:hidden path="amendmentType"/>
                    </c:if>
                    
                    <c:set var='isDisabled' value="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 'false' : 'true'}" />
                    
					<c:choose>
						<c:when test="${isDisabled eq 'true'}">
							<c:if test="${not empty  ofcRequestModel.amendmentTypesAsArray}" >
								<br />
								<table style="width:100%;display:block; color: #666666;font-size: 12px;">
									<c:forEach items="${ofcRequestModel.amendmentTypesAsArray}" var="type">
									<tr style="width: 100%">
										<td style='width:5%'>
											<img src="resources/images/common/bullet.gif" width="11px" height="8px"/>
										</td>
										<td style='width:95%'>
											<c:set var="typeStr" >${type.propertyName}</c:set>
											<c:set var="underscoredType" value='<%=UtilCommon.underscore((String)pageContext.getAttribute("typeStr")) %>' />
											<spring:message code="${underscoredType}" />
										</td>
									</tr>
									</c:forEach>
								</table>
							</c:if>
						</c:when>
						<c:otherwise>
							<form:select name="select" class="multiple" path="amendmentType" multiple="true"  style="height:105px">
								<c:forEach items="${ofcRequestModel.amendmentTypes}" var="optionType">
									<c:set var="typeStr" value='${optionType.propertyName}' />
									<c:set var="underscoredType" value='<%=UtilCommon.underscore((String)pageContext.getAttribute("typeStr")) %>' />
									<c:set var="selected" value=""/>
									<c:choose>
									<c:when test="${(not empty  ofcRequestModel.amendmentTypesAsArray)}">
										<c:forEach items="${ofcRequestModel.amendmentTypesAsArray}" var="type">
											<c:set var="typeStrValue" >${type.propertyName}</c:set>
											<c:set var="underscoredTypeArray" value='<%=UtilCommon.underscore((String)pageContext.getAttribute("typeStrValue")) %>' />
											<c:if test="${underscoredTypeArray eq underscoredType}">
												<c:set var="selected" value="selected"/>
											</c:if>
										</c:forEach>
									</c:when>
									</c:choose>	
									<form:option value="${optionType.propertyName}" selected="${selected}">
										<spring:message code="${underscoredType}"/>
									</form:option>
								</c:forEach>
							</form:select>
							<div class="brk"></div>
							<div class="t_manad-cont">
                            	<spring:message code="label.amendment.multiselection"/>
                            </div>
						</c:otherwise>
					</c:choose>

			</div>
		</div>
	</c:when>
</c:choose> <c:choose>
			<c:when test="${(ofcRequestModel.type eq 'Renewal') or (ofcRequestModel.imsLogId != null and (not empty ofcRequestModel.imsLogId))}">
				<div class="brk"></div>
				<div id="renewal">
					<fieldset>
						<legend>
							<spring:message code="label.request.imsLogId" />
						</legend>
					</fieldset>
					<div class="t_form-left">
						<label> <spring:message code="label.request.imsLogId" />
							<span class="t_star"><spring:message code="label.required" />
						</span>:</label>
						<form:input type="text" class="${((null == ofcRequestModel.status) || (ofcRequestModel.status == 'Return_For_Update') || (empty ofcRequestModel.status)) ? 't_form-fld' : 't_form-fld-readonly'}" path="imsLogId"
							readonly="${((null == ofcRequestModel.status) || ((ofcRequestModel.status == 'Return_For_Update') and (ofcRequestModel.type eq 'Renewal')) || (empty ofcRequestModel.status)) ? 'false' : 'true'}" maxlength="10"/>
					</div>
				</div>
			</c:when>
</c:choose>
		<div class="brk"></div>
		<c:choose>
			<c:when
				test="${((ofcRequestModel.status eq 'Additional_Payment_Required') or (ofcRequestModel.status eq 'Non_Compliance_Comments_Exists') or (ofcRequestModel.status eq 'Approved') or (ofcRequestModel.status eq 'Return_For_Update') or (empty ofcRequestModel.status) or (ofcRequestModel.status eq null))}">

					<fieldset>
                        <legend><spring:message code="label.request.documents" /></legend>
                    </fieldset>
                    <div class="brk"></div>
                    <div class="t_manad-cont">
                            	<spring:message code="label.request.documentType.add.info"/>
                     </div>
                     <div class="brk"></div>
					<a href="javascript:void(0);" id="add_document_type_container" onclick="addRow('documents', '${requestScope.requestContextAttribute.locale.language}');">
						<img src="resources/images/add.png" width="16px" height="16px"/>
					<div id="add_document_type"><spring:message code="label.request.documentType.add" /></div>
					</a>
			</c:when>
		</c:choose> <!--form right close-->
		<table id="documents" class="grdView">
			<caption><spring:message code="label.request.documentsHead" /></caption>
			<colgroup>
				<col width="30%" />
				<col width="60%" />
				<col width="10%" />
			</colgroup>
			<tr>
				<th><spring:message code="label.request.document.type" /></th>
				<th><spring:message code="label.request.document.uploadedFile" />
				</th>
				<th><spring:message code="label.request.document.actions" /></th>
			</tr>
			<c:forEach var="document" items="${ofcRequestModel.documents}"
				varStatus="status">
				<tr id="documentRow" ${status.index % 2 == 0 ? 'class="grdAltRow"' : ''}>
					<td>
						<form:hidden path="documents[${status.index}].documentType.id" />
						<form:hidden path="documents[${status.index}].id" /> 
						<form:hidden path="documents[${status.index}].documentLocation" style="display:none" />
						<form:hidden path="documents[${status.index}].documentName" style="display:none" />
						<c:choose>
							<c:when
								test='${requestScope.requestContextAttribute.locale.language eq "ar"}'>
								<form:hidden
									path="documents[${status.index}].documentType.arabicName"/>${document.documentType.arabicName}
							</c:when>
							<c:otherwise>
								<form:hidden
									path="documents[${status.index}].documentType.englishName"/>${document.documentType.englishName}
							</c:otherwise>
						</c:choose> </td>
					<c:choose>
						<c:when
							test='${((document.documentLocation != null) or (!(empty document.documentLocation)))}'>
							<td><a href="common/download.htm?fileId=${document.id}">${document.documentName}</a>
							</td>
							<td></td>
						</c:when>

						<c:when
							test='${((document.documentLocation == null) or (empty document.documentLocation)) and ((ofcRequestModel.multipartFiles) != null or (empty ofcRequestModel.multipartFiles))}'>
							<td><form:input path="multipartFiles[${status.index}]"
									type="file" size="40" /></td>
							<td class="actions"><img
								src="resources/images/common/cancel_doc_icon.png"
								onclick="deleteRow('documents',this.parentNode.parentNode.rowIndex,'${requestScope.requestContextAttribute.locale.language}','<spring:message code="label.document.delete.successMessage"/>');" />
							</td>
						</c:when>
					</c:choose>
				</tr>
			</c:forEach>
		</table>
		<div class="brk"></div> <form:hidden path="type" /> <input
		type="hidden" name="action" id="action" /> <c:choose>
			<c:when
				test='<%=(type.equals(GlobalConstants.MY_INBOX) ) || (type.equals(GlobalConstants.MY_REQUESTS))%>'>
				<c:set var="officerUserType" value="<%=UserType.Officer %>"/>
				<table id="Table1" class="grdView">
					<caption>
						<spring:message code="label.request.history.action" />
					</caption>
					<colgroup>
						<col width="18%" />
						<col width="23%" />
						<col width="23%" />
						<col width="39%" />
					</colgroup>
					<tr>
						<th><spring:message code="label.request.history.actionTaken" />
						</th>
						<th><spring:message code="label.request.history.username" />
						</th>
						<th><spring:message code="label.request.history.dateTime" />
						</th>
						<th><spring:message code="label.request.history.comments" />
						</th>
					</tr>

					<c:forEach items="${ofcRequestModel.ofcHistory}" var="history"
						varStatus="loopStatus">
						<tr ${loopStatus.index % 2 == 0 ? 'class="grdAltRow"' : ''}>
							<td><spring:message code="${history.status}" /></td>
							<td>
								<c:choose>
									<c:when test="${history.executer == officerUserType}" >
										${history.officerId}
									</c:when>
									<c:otherwise>
										${history.userId}
									</c:otherwise>
								</c:choose>
							</td>
							<td><fmt:formatDate value="${history.processingDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_DATE_FORMAT%>"/></td>
							<td>${history.officerComments}</td>
						</tr>
					</c:forEach>

				</table>

		</c:when>
		</c:choose>
			<c:if
				test="${(null != ofcRequestModel.comments) and (not empty ofcRequestModel.comments)}">
				<div class="brk"></div>
				<table id="Table2" class="grdView">
					<caption>
						<spring:message code="label.request.nonComplianceComment" />
					</caption>
					<colgroup>
						<col width="6%" />
						<col width="30%" />
						<col width="8%" />
						<col width="8%" />
						<col width="13%" />
						<col width="11%" />
						<col width="24%" />
					</colgroup>
					<tr>
						<th><spring:message
								code="label.request.nonComplianceComment.id" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.comment" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.severity" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.entryDate" /><br />
						<spring:message code="label.request.dateFormat" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.inspectorName" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.section" />
						</th>
						<th><spring:message
								code="label.request.nonComplianceComment.reply" />
						</th>
					</tr>
					<c:forEach items="${ofcRequestModel.comments}" var="comment" varStatus="loopStatus">
						<tr ${loopStatus.index % 2 == 0 ? 'class="grdAltRow"' : ''}>
							<td>${comment.id}</td>
							<td>${comment.commentDetails}</td>
							<td>${comment.imsSeverity}</td>
							<td><fmt:formatDate value="${comment.commentDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_DATE_FORMAT%>"/></td>
							<td>${comment.imsInspectorName}</td>
							<td>${comment.imsDeptId}</td>
							<td>
								<c:choose>
									<c:when test="${ofcRequestModel.status ne 'Non_Compliance_Comments_Exists'}">
										${comment.reply}
									</c:when>
									<c:otherwise>
										<c:if test="${comment.replied eq true}">
											${comment.reply}
											<form:hidden path="comments[${loopStatus.index}].reply"/>
										</c:if>
										<c:if test="${comment.replied eq false}">
											<form:textarea class="t_address" path="comments[${loopStatus.index}].reply"/>
										</c:if>
									</c:otherwise>
								</c:choose>
							</td>
						</tr>
					</c:forEach>
				</table>

			</c:if>
		<c:if
			test="${(null != ofcRequestModel.fnpList) || (not empty ofcRequestModel.fnpList)}">
			<div class="brk"></div>
			<fieldset>
                    <legend><spring:message code="label.request.fees" /></legend>
 			</fieldset>
 			<div class="brk"></div>
			<c:forEach items="${ofcRequestModel.fnpList}" var="fnp" varStatus="fnpVarStatus">
				<c:set var="fees" scope="request" value="${fnp.fees}"/>  
					
					<%
						BigDecimal formattedFees = new BigDecimal((Float)request.getAttribute("fees"));
						String decimalFormat = new DecimalFormat(GlobalConstants.FEES_FORMAT).format(formattedFees);
					%>
				<c:choose>
					<c:when test="${fnpVarStatus.index == 0}">
					
						<div class="t_form-left">
							<label><spring:message code="label.request.fees" /><span class="t_star"></span>:</label>
							<input type="text" class="t_form-fld-readonly"  disabled="disabled" value="<%=decimalFormat%>"/>
							<span class="fees_currency"><spring:message code="fnp.fees.currency" /></span>
						</div>
						<div class="t_form-right">
							<label><spring:message code="label.request.paymentAdviceNo" /></label>
							<input type="text" class="t_form-fld-readonly"  disabled="disabled" value="${fnp.paymentNumber}"/>
						</div>
					</c:when>
					<c:otherwise>
						<div class="t_form-left">
							<label><spring:message code="label.request.additionalFees" /><span class="t_star"></span>:</label>
							<input type="text" class="t_form-fld-readonly"  disabled="disabled" value="<%=decimalFormat%>"/>
							<span class="fees_currency"><spring:message code="fnp.fees.currency" /></span>
						</div>
						<div class="t_form-right">
							<label><spring:message code="label.request.addPaymentAdviceNo" /></label>
							<input type="text" class="t_form-fld-readonly"  disabled="disabled" value="${fnp.paymentNumber}"/>
						</div>
					</c:otherwise>
				</c:choose>
						<div class="brk"></div>
			</c:forEach>
		</c:if>
		<div class="brk"></div>

	<form:hidden path="trakheesId"/>

		<div id="fm-submit">
			<c:choose>
				<c:when
					test="${(null == ofcRequestModel.status) or (empty ofcRequestModel.status)}">

					<div class="t_manad-cont">
						<spring:message code="label.request.generalMessage" />
						<span class="t_star"><spring:message code="label.required" />
						</span>
						<spring:message code="label.request.generalMessage.mandatory" />
					</div>
					
						<button type="button" class="btn_bg" id="submitButton"
							name="submitButton" onclick="validate('documents', 'create');">
							<spring:message code="label.request.button.submit" />
						</button>
					
				</c:when>
				<c:when test="${ofcRequestModel.status == 'Approved'}">
					
						<button type="button" class="btn_bg" id="paymentDone"
							name="paymentDone"
							onclick="validate('documents', 'payment_done');">
							<spring:message code="label.request.button.paymentDone" />
						</button>
					
				</c:when>
				
				<c:when test="${ofcRequestModel.status == 'Additional_Payment_Required'}">
					
						<button type="button" class="btn_bg" id="additionalPaymentDone"
							name="additionalPaymentDone"
							onclick="validate('documents', 'additional_payment_done');">
							<spring:message code="label.request.button.additionalPaymentDone" />
						</button>
					
				</c:when>
				
				<c:when test="${ofcRequestModel.status == 'Return_For_Update'}">
					
						<button type="button" class="btn_bg" id="resubmit" name="resubmit"
							onclick="validate('documents', 'submit');">
							<spring:message code="label.request.button.resubmit" />
						</button>
					
				</c:when>
				<c:when
					test="${ofcRequestModel.status == 'Non_Compliance_Comments_Exists'}">
					
						<button type="button" class="btn_bg" id="reinscpectin"
							name="reinscpectin"
							onclick="validate('documents', 'Non-Compliance_comments_exist');">
							<spring:message code="label.request.button.replyComments" />
						</button>
					
				</c:when>
			</c:choose>
		</div> <form:hidden path="id" /> <form:hidden path="processId" /> <form:hidden
			path="officerId" /> <form:hidden path="userId" />

		<div class="brk"></div>
</form:form>